<template>
    <a-drawer :title="formData.id ? '编辑手机端可用应用列表' : '增加手机端可用应用列表'" :width="600" :visible="visible"
        :destroy-on-close="true" :footer-style="{ textAlign: 'right' }" @close="onClose">
        <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
            <a-form-item label="应用表id：" name="appId">
                <a-input v-model:value="formData.appId" placeholder="请输入应用表id" allow-clear />
            </a-form-item>
            <a-form-item label="应用编号id：" name="appCode">
                <a-input v-model:value="formData.appCode" placeholder="请输入应用编号id" allow-clear />
            </a-form-item>
            <a-form-item label="移动端appId：" name="appAppId">
                <a-input v-model:value="formData.appAppId" placeholder="请输入移动端appId" allow-clear />
            </a-form-item>
            <a-form-item label="移动端版本号：" name="appVersion">
                <a-input v-model:value="formData.appVersion" placeholder="请输入移动端版本号" allow-clear />
            </a-form-item>
            <a-form-item label="移动端类型：" name="appType">
                <a-input v-model:value="formData.appType" placeholder="请输入移动端类型" allow-clear />
            </a-form-item>
            <a-form-item label="状态：" name="status">
                <a-input v-model:value="formData.status" placeholder="请输入状态" allow-clear />
            </a-form-item>
            <a-form-item label="activity_name：" name="activityName">
                <a-input v-model:value="formData.activityName" placeholder="请输入activity_name" allow-clear />
            </a-form-item>
            <a-form-item label="app_id_list：" name="appIdList">
                <a-input v-model:value="formData.appIdList" placeholder="请输入app_id_list" allow-clear />
            </a-form-item>
            <a-form-item label="bundle_id：" name="bundleId">
                <a-input v-model:value="formData.bundleId" placeholder="请输入bundle_id" allow-clear />
            </a-form-item>
            <a-form-item label="compel_update_version：" name="compelUpdateVersion">
                <a-input v-model:value="formData.compelUpdateVersion" placeholder="请输入compel_update_version"
                    allow-clear />
            </a-form-item>
            <a-form-item label="介绍：" name="description">
                <a-input v-model:value="formData.description" placeholder="请输入介绍" allow-clear />
            </a-form-item>
            <a-form-item label="应用地址：" name="entryUrl">
                <a-input v-model:value="formData.entryUrl" placeholder="请输入应用地址" allow-clear />
            </a-form-item>
            <a-form-item label="图片：" name="icon">
                <a-input v-model:value="formData.icon" placeholder="请输入图片" allow-clear />
            </a-form-item>
            <a-form-item label="inst_url：" name="instUrl">
                <a-input v-model:value="formData.instUrl" placeholder="请输入inst_url" allow-clear />
            </a-form-item>
            <a-form-item label="是否门户：" name="isCloudApp">
                <a-input v-model:value="formData.isCloudApp" placeholder="请输入是否门户" allow-clear />
            </a-form-item>
            <a-form-item label="应用名称：" name="name">
                <a-input v-model:value="formData.name" placeholder="请输入应用名称" allow-clear />
            </a-form-item>
            <a-form-item label="是否展示图标：" name="isShow">
                <a-input v-model:value="formData.isShow" placeholder="请输入" allow-clear />
            </a-form-item>
            <a-form-item label="old_app_type：" name="oldAppType">
                <a-input v-model:value="formData.oldAppType" placeholder="请输入old_app_type" allow-clear />
            </a-form-item>
            <a-form-item label="package_name：" name="packageName">
                <a-input v-model:value="formData.packageName" placeholder="请输入package_name" allow-clear />
            </a-form-item>
            <a-form-item label="参数信息：" name="params">
                <a-input v-model:value="formData.params" placeholder="请输入参数信息" allow-clear />
            </a-form-item>
            <a-form-item label="preview：" name="preview">
                <a-input v-model:value="formData.preview" placeholder="请输入preview" allow-clear />
            </a-form-item>
            <a-form-item label="third_party_checkAddress：" name="thirdPartyCheckaddress">
                <a-input v-model:value="formData.thirdPartyCheckaddress" placeholder="请输入third_party_checkAddress"
                    allow-clear />
            </a-form-item>
            <a-form-item label="update_info：" name="updateInfo">
                <a-input v-model:value="formData.updateInfo" placeholder="请输入update_info" allow-clear />
            </a-form-item>
            <a-form-item label="update_type：" name="updateType">
                <a-input v-model:value="formData.updateType" placeholder="请输入update_type" allow-clear />
            </a-form-item>
            <a-form-item label="url_scheme：" name="urlScheme">
                <a-input v-model:value="formData.urlScheme" placeholder="请输入url_scheme" allow-clear />
            </a-form-item>
            <a-form-item label="应用分类：" name="appCategory">
                <a-input v-model:value="formData.appCategory" placeholder="请输入应用分类" allow-clear />
            </a-form-item>
            <a-form-item label="权限 全部0  白名单1：" name="permission">
                <a-input v-model:value="formData.permission" placeholder="请输入权限 全部0  白名单1" allow-clear />
            </a-form-item>
        </a-form>
        <template #footer>
            <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
            <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
        </template>
    </a-drawer>
</template>

<script setup name="appInfoForegroundForm">
import { cloneDeep } from 'lodash-es'
import { required } from '@/utils/formRules'
import appInfoForegroundApi from '@/api/biz/appInfoForegroundApi'
// 抽屉状态
const visible = ref(false)
const emit = defineEmits({ successful: null })
const formRef = ref()
// 表单数据
const formData = ref({})
const submitLoading = ref(false)

// 打开抽屉
const onOpen = (record) => {
    visible.value = true
    if (record) {
        let recordData = cloneDeep(record)
        formData.value = Object.assign({}, recordData)
    }
}
// 关闭抽屉
const onClose = () => {
    formRef.value.resetFields()
    formData.value = {}
    visible.value = false
}
// 默认要校验的
const formRules = {
}
// 验证并提交数据
const onSubmit = () => {
    formRef.value
        .validate()
        .then(() => {
            submitLoading.value = true
            const formDataParam = cloneDeep(formData.value)
            appInfoForegroundApi
                .appInfoForegroundSubmitForm(formDataParam, !formDataParam.id)
                .then(() => {
                    onClose()
                    emit('successful')
                })
                .finally(() => {
                    submitLoading.value = false
                })
        })
}
// 抛出函数
defineExpose({
    onOpen
})
</script>
